package com.xz.courseschedule.controller;

import com.xz.courseschedule.entity.Task;
import com.xz.courseschedule.service.TaskService;
import com.xz.courseschedule.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 教学任务管理控制器
 * @Author: zys
 * @CreateTime: 2025-05-23
 */
@Tag(name = "教学任务管理", description = "教学任务的管理和自动排课功能")
@RestController
@RequestMapping("/task")
public class TaskController {
    @Autowired
    private TaskService taskService;

    @Operation(summary = "获取教学任务列表", description = "获取系统中所有教学任务的信息列表")
    @GetMapping("/getList")
    public Result getList(){
        return taskService.getList();
    }

    @Operation(summary = "根据ID获取教学任务", description = "根据任务ID获取单个教学任务的详细信息")
    @Parameter(name = "id", description = "任务ID", required = true)
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable Long id){
        return taskService.getById(id);
    }

    @Operation(summary = "新增教学任务", description = "添加新的教学任务到系统中")
    @PostMapping("/add")
    public Result add(@RequestBody Task task){
        return taskService.add(task);
    }

    @Operation(summary = "更新教学任务", description = "更新指定的教学任务信息")
    @PutMapping("/update")
    public Result update(@RequestBody Task task){
        return taskService.update(task);
    }

    @Operation(summary = "删除教学任务", description = "根据任务ID删除指定的教学任务")
    @Parameter(name = "id", description = "任务ID", required = true)
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id){
        return taskService.delete(id);
    }

    @Operation(summary = "批量删除教学任务", description = "根据任务ID列表批量删除教学任务")
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody Long[] ids){
        return taskService.deleteBatch(ids);
    }

    @Operation(summary = "自动排课", description = "基于遗传算法对指定学期的教学任务进行自动排课，排课结果存入课表")
    @Parameter(name = "id", description = "学期ID", required = true)
    @PostMapping("/autoSchedule/{id}")
    public Result autoSchedule(@PathVariable Long id){
        return taskService.courseScheduling(id);
    }
}
